<form id="releaseModal" class="modal fade form-horizontal" name="releaseForm" valdr-type="Release"
    ng-submit="release()">
    <!--
      ~ Copyright 2024 Apollo Authors
      ~
      ~ Licensed under the Apache License, Version 2.0 (the "License");
      ~ you may not use this file except in compliance with the License.
      ~ You may obtain a copy of the License at
      ~
      ~ http://www.apache.org/licenses/LICENSE-2.0
      ~
      ~ Unless required by applicable law or agreed to in writing, software
      ~ distributed under the License is distributed on an "AS IS" BASIS,
      ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      ~ See the License for the specific language governing permissions and
      ~ limitations under the License.
      ~
    -->
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header panel-primary">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" ng-show="!toReleaseNamespace.isBranch">
                    {{'Component.Publish.Title' | translate }}
                    <small>{{'Component.Publish.Tips' | translate:this }}</small>
                </h4>
                <h4 class="modal-title" ng-show="toReleaseNamespace.isBranch && !toReleaseNamespace.mergeAndPublish">
                    {{'Component.Publish.Grayscale' | translate }}
                    <small>{{'Component.Publish.GrayscaleTips' | translate }}</small>
                </h4>
                <h4 class="modal-title" ng-show="toReleaseNamespace.isBranch && toReleaseNamespace.mergeAndPublish">
                    {{'Component.Publish.AllPublish' | translate }}
                    <small>{{'Component.Publish.AllPublishTips' | translate }}</small>
                </h4>

            </div>

            <div class="release modal-body">

                <div class="form-group pre-scrollable">
                    <div class="col-sm-2 control-label">
                        <div class="btn-group-vertical" ng-if="!toReleaseNamespace.isPropertiesFormat || (toReleaseNamespace.isBranch && !toReleaseNamespace.mergeAndPublish)">
                            <div class="btn-group btn-group-xs" role="group">
                                <button type="button" class="btn btn-default" ng-if="toReleaseNamespace.isBranch"
                                        ng-class="{active:releaseChangeViewType=='compareWithMasterValue'}"
                                        ng-click="switchReleaseChangeViewType('compareWithMasterValue')">{{'Component.Publish.CompareWithMasterValue' | translate }}
                                </button>
                                <button type="button" class="btn btn-default"
                                    ng-class="{active:releaseChangeViewType=='compareWithPublishedValue'}"
                                    ng-click="switchReleaseChangeViewType('compareWithPublishedValue')">{{'Component.Publish.CompareWithPublishedValue' | translate }}
                                </button>
                                <button type="button" class="btn btn-default"
                                    ng-class="{active:releaseChangeViewType=='release'}"
                                    ng-click="switchReleaseChangeViewType('release')">{{'Component.Publish.PublishedValue' | translate }}
                                </button>
                            </div>
                        </div>
                        <label ng-if="toReleaseNamespace.isPropertiesFormat" style="display: block">{{'Component.Publish.Changes' | translate }}</label>
                    </div>

                    <div class="col-sm-10"
                        ng-if="(!toReleaseNamespace.isBranch && toReleaseNamespace.itemModifiedCnt)
                                    || (toReleaseNamespace.isBranch && toReleaseNamespace.itemModifiedCnt)
                                    || (toReleaseNamespace.isBranch && toReleaseNamespace.mergeAndPublish && toReleaseNamespace.branchItems.length)"
                        valdr-form-group>

                        <!--properties format-->
                        <!--normal release-->
                        <!--主版本发布-->
                        <table class="table table-bordered table-striped text-center table-hover table-fixed"
                            ng-if="toReleaseNamespace.isPropertiesFormat && !toReleaseNamespace.isBranch">
                            <thead>
                                <tr>
                                    <th width="12%">
                                        {{'Component.Publish.Key' | translate }}
                                    </th>
                                    <th>
                                        {{'Component.Publish.PublishedValue' | translate }}
                                    </th>
                                    <th width="50%">
                                        {{'Component.Publish.NoPublishedValue' | translate }}
                                    </th>
                                    <th width="12%">
                                        {{'Component.Publish.ModifyRecord' | translate }}
                                    </th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr ng-repeat="config in toReleaseNamespace.items"
                                    ng-if="config.item.key && config.isModified">
                                    <td width="20%" title="{{config.item.key}}">
                                        <span ng-bind="config.item.key"></span>
                                        <span class="label label-success" ng-if="config.isModified && !config.oldValue"
                                            data-tooltip="tooltip" data-placement="bottom"
                                            title="{{'Component.Publish.NewAddedTips' | translate }}">{{'Component.Publish.NewAdded' | translate }}</span>
                                        <span class="label label-info"
                                            ng-if="config.isModified && config.oldValue && !config.isDeleted"
                                            data-tooltip="tooltip" data-placement="bottom"
                                            title="{{'Component.Publish.ModifiedTips' | translate }}">{{'Component.Publish.Modified' | translate }}</span>
                                        <span class="label label-danger" ng-if="config.isDeleted" data-tooltip="tooltip"
                                            data-placement="bottom"
                                            title="{{'Component.Publish.DeletedTips' | translate }}">{{'Component.Publish.Deleted' | translate }}</span>
                                    </td>
                                    <td width="25%" title="{{config.oldValue}}">
                                        <span ng-bind="config.oldValue"></span>
                                    </td>
                                    <td width="25%" title="{{config.newValue}}" class="left-overflow">
                                        <apollodiff old-str="config.oldValue" new-str="config.newValue" apollo-id="'diffWithPublished:'+config.item.key"></apollodiff>
                                    </td>
                                    <td width="15%">
                                        <span class="block" ng-bind="config.item.dataChangeLastModifiedBy"></span>
                                        <span class="block"  ng-bind="config.item.dataChangeLastModifiedTime | date: 'yyyy-MM-dd'"></span>
                                        <span class="block"  ng-bind="config.item.dataChangeLastModifiedTime | date: 'HH:mm:ss'"></span>
                                    </td>
                                </tr>
                            </tbody>
                        </table>

                        <!--branch gray release-->
                        <!--灰度发布-->
                        <table class="table table-bordered table-striped text-center table-hover table-fixed" ng-if="toReleaseNamespace.isPropertiesFormat &&
                               toReleaseNamespace.isBranch && !toReleaseNamespace.mergeAndPublish">
                            <thead>
                                <tr>
                                    <th width="12%">
                                        {{'Component.Publish.Key' | translate }}
                                    </th>
                                    <th ng-if="isCompareMaster || isNoCompare">
                                        {{'Component.Publish.MasterValue' | translate }}
                                    </th>
                                    <th ng-if="isComparePublished || isNoCompare">
                                        {{'Component.Publish.GrayPublishedValue' | translate }}
                                    </th>
                                    <th ng-if="isNoCompare">{{'Component.Publish.GrayNoPublishedValue' | translate }}</th>
                                    <th ng-if="!isNoCompare" width="50%">{{'Component.Publish.GrayNoPublishedValue' | translate }}</th>
                                    <th width="12%">
                                        {{'Component.Publish.ModifyRecord' | translate }}
                                    </th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr ng-repeat="config in toReleaseNamespace.branchItems"
                                    ng-if="config.isModified || config.isDeleted">
                                    <td width="15%" title="{{config.item.key}}">
                                        <span ng-bind="config.item.key"></span>
                                        <span class="label label-danger"
                                            ng-show="config.isDeleted">{{'Component.Publish.Deleted' | translate }}</span>
                                    </td>
                                    <td width="20%" title="{{config.masterReleaseValue}}" ng-if="isCompareMaster || isNoCompare">
                                        <span ng-bind="config.masterReleaseValue"></span>
                                    </td>
                                    <td width="20%" title="{{config.oldValue}}" ng-if="isComparePublished || isNoCompare">
                                        <span ng-bind="config.oldValue"></span>
                                    </td>
                                    <td width="20%" title="{{config.newValue}}" class="left-overflow">
                                        <span ng-if="isCompareMaster">
                                            <apollodiff old-str="config.masterReleaseValue" new-str="config.newValue" apollo-id="'grayDiffWithMaster:' + config.item.key"></apollodiff>
                                        </span>
                                        <span ng-if="isComparePublished">
                                            <apollodiff old-str="config.oldValue" new-str="config.newValue" apollo-id="'grayDiffWithPublished:' + config.item.key"></apollodiff>
                                        </span>
                                        <span ng-if="isNoCompare" ng-bind="config.newValue"></span>
                                    </td>
                                    <td>
                                        <span class="block" ng-bind="config.item.dataChangeLastModifiedBy"></span>
                                        <span class="block" ng-bind="config.item.dataChangeLastModifiedTime | date: 'yyyy-MM-dd'"></span>
                                        <span class="block" ng-bind="config.item.dataChangeLastModifiedTime | date: 'HH:mm:ss'"></span>
                                    </td>
                                </tr>
                            </tbody>
                        </table>

                        <!--branch updateAndPublish and publish-->
                        <!--灰度推全-->
                        <table class="table table-bordered table-striped text-center table-hover table-fixed" ng-if="toReleaseNamespace.isPropertiesFormat &&
                               toReleaseNamespace.isBranch && toReleaseNamespace.mergeAndPublish">
                            <thead>
                                <tr>
                                    <th width="12%">
                                        {{'Component.Publish.Key' | translate }}
                                    </th>
                                    <th>
                                        {{'Component.Publish.MasterValue' | translate }}
                                    </th>
                                    <th width="50%">
                                        {{'Component.Publish.GrayValue' | translate }}
                                    </th>
                                    <th width="12%">
                                        {{'Component.Publish.ModifyRecord' | translate }}
                                    </th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr ng-repeat="config in toReleaseNamespace.branchItems" ng-if="!config.isDeleted">
                                    <td width="20%" title="{{config.item.key}}">
                                        <span ng-bind="config.item.key"></span>
                                    </td>
                                    <td width="25%" title="{{config.masterReleaseValue}}">
                                        <span ng-bind="config.masterReleaseValue"></span>
                                    </td>
                                    <td width="25%" title="{{config.item.value}}" class="left-overflow">
                                        <apollodiff old-str="config.masterReleaseValue" new-str="config.item.value" apollo-id="'grayDiffMasterReleased:' + config.item.key"></apollodiff>
                                    </td>
                                    <td width="15%">
                                        <span class="block" ng-bind="config.item.dataChangeLastModifiedBy"></span>
                                        <span class="block" ng-bind="config.item.dataChangeLastModifiedTime | date: 'yyyy-MM-dd'"></span>
                                        <span class="block" ng-bind="config.item.dataChangeLastModifiedTime | date: 'HH:mm:ss'"></span>
                                    </td>
                                </tr>
                            </tbody>
                        </table>

                        <!--file format -->
                        <div ng-repeat="config in toReleaseNamespace.branchItems" ng-if="!toReleaseNamespace.isPropertiesFormat&&toReleaseNamespace.isBranch"
                             ng-show="releaseChangeViewType=='compareWithMasterValue'">
                            <apollodiff old-str="config.masterReleaseValue" new-str="config.newValue" apollo-id="'releaseStrDiffWithMasterValue'">
                            </apollodiff>
                        </div>
                        <div ng-repeat="item in toReleaseNamespace.items" ng-if="!toReleaseNamespace.isPropertiesFormat"
                            ng-show="releaseChangeViewType=='compareWithPublishedValue'">
                            <apollodiff old-str="item.oldValue" new-str="item.newValue" apollo-id="'releaseStrDiffWithPublishedValue'">
                            </apollodiff>
                        </div>
                        <div ng-repeat="item in toReleaseNamespace.items" ng-if="!toReleaseNamespace.isPropertiesFormat"
                            ng-show="releaseChangeViewType=='release'">
                            <textarea class="form-control no-radius" rows="20" ng-disabled="true"
                                ng-show="item.newValue" ng-bind="item.newValue">
                                        </textarea>
                        </div>

                    </div>
                    <div class="col-sm-5"
                        ng-show="(!toReleaseNamespace.isBranch && !toReleaseNamespace.itemModifiedCnt)"
                        valdr-form-group>
                        <label class="form-control-static">
                            {{'Component.Publish.ItemNoChange' | translate }}
                        </label>
                    </div>
                    <div class="col-sm-5"
                        ng-show="(toReleaseNamespace.isBranch && !toReleaseNamespace.mergeAndPublish && !toReleaseNamespace.itemModifiedCnt)"
                        valdr-form-group>
                        <label class="form-control-static">
                            {{'Component.Publish.GrayItemNoChange' | translate }}
                        </label>
                    </div>
                    <div class="col-sm-5"
                        ng-show="(toReleaseNamespace.isBranch && toReleaseNamespace.mergeAndPublish && toReleaseNamespace.branchItems.length == 0)"
                        valdr-form-group>
                        <label class="form-control-static">
                            {{'Component.Publish.NoGrayItems' | translate }}
                        </label>
                    </div>

                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">
                        <apollorequiredfield></apollorequiredfield>
                        {{'Component.Publish.Release' | translate }}
                    </label>
                    <div class="col-sm-5" valdr-form-group>
                        <input type="text" name="releaseName" class="form-control" placeholder="input release name"
                            ng-model="toReleaseNamespace.releaseTitle" ng-required="true">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">{{'Component.Publish.ReleaseComment' | translate }}</label>
                    <div class="col-sm-10" valdr-form-group>
                        <textarea rows="2" name="comment" class="form-control"
                            ng-model="releaseComment" placeholder="Add an optional extended description..."></textarea>
                    </div>
                </div>


            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-default"
                    data-dismiss="modal">{{'Common.Cancel' | translate }}</button>
                <button type="submit" class="btn btn-primary"
                    ng-disabled="releaseForm.$invalid || releaseBtnDisabled
                        || (toReleaseNamespace.isBranch && toReleaseNamespace.mergeAndPublish && toReleaseNamespace.branchItems.length == 0)">
                    {{'Component.Publish.OpPublish' | translate }}
                </button>
            </div>
        </div>
    </div>
</form>
